package cn.rkylin.oms.ext.cainiao.stockin.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.ext.cainiao.stockin.domain.StockIn;
import cn.rkylin.oms.ext.cainiao.stockin.domain.StockinType;
import cn.rkylin.oms.ext.cainiao.stockin.vo.StockInVO;

/**
 * 入库DAO
 *
 * @author 齐涛
 * @version 1.0
 * @created 11-9-2017 10:51:30
 */
@Repository(value = "cainiaoStockInDAO")
public class StockInDAOImpl implements StockInDAO {

	@Autowired
	protected IDataBaseFactory dao;

	/**
	 * 查询入库单信息
	 *
	 * @param stockInVO
	 *            入库单VO
	 * @return 入库单信息
	 * @throws Exception
	 *             异常
	 */
	public StockInVO getStockInInfo(StockInVO stockInVO) throws Exception {
		List<StockInVO> list = dao.findAllList("getCainiaoStockInInfo", stockInVO);

		if (list != null && list.size() > 0) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * 更新入库单
	 *
	 * @param stockIn
	 *            入库单bean
	 * @return 更新条数
	 * @throws Exception
	 *             异常
	 */
	public int updateStockIn(StockIn stockIn) throws Exception {
		return dao.update("updateCainiaoStockIn", stockIn);
	}

	/**
	 * 删除入库单
	 *
	 * @param stockIn
	 *            入库单bean
	 * @return 删除条数
	 * @throws Exception
	 *             异常
	 */
	public int deleteStockIn(StockIn stockIn) throws Exception {
		return dao.delete("deleteCainiaoStockIn", stockIn);
	}

	/**
	 * 添加入库单
	 *
	 * @param stockIn
	 *            入库单bean
	 * @return 添加条数
	 * @throws Exception
	 *             异常
	 */
	public int insertStockIn(StockIn stockIn) throws Exception {
		return dao.insert("insertCainiaoStockIn", stockIn);
	}

	/**
	 * 查询入库单信息(更新在途数)
	 *
	 * @param stockInVO
	 * @return
	 * @throws Exception
	 */
	public StockInVO getStockInInfoForUpdateOnwayQty(StockInVO stockInVO) throws Exception {
		List<StockInVO> list = dao.findAllList("getCainiaoStockInInfoForUpdateOnwayQty", stockInVO);

		if (list != null && list.size() > 0) {
			return list.get(0);
		}

		return null;
	}

	/**
	 * 查询入库类型列表
	 *
	 * @return
	 * @throws Exception
	 */
	public List<StockinType> selectStockinTypeList() throws Exception {
		return dao.findList("selectCainiaoStockinTypeList", "");
	}

}
